package com.market.controller.admin;

import com.market.bean.MarketUser;
import com.market.bean.common.BasePageInfo;
import com.market.bean.common.BaseRespVo;
import com.market.bean.common.CommonData;
import com.market.bean.validation.ValidationUser;
import com.market.exception.ValidationException;
import com.market.mapper.MarketUserMapper;
import com.market.service.admin.AdminUserService;
import com.market.utils.ValidationUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 *
 */
@RestController
@RequestMapping("admin/user")
public class AdminUserController {
    @Autowired
    AdminUserService userService;


    // 将Handler方法和权限建立耦合关系，访问这个Handler方法需要注解中的权限
    // @RequiresPermissions("aaa")
    @RequestMapping("list")
    public BaseRespVo<CommonData> list(BasePageInfo info, /*@Validated*/ ValidationUser user/*, BindingResult bindingResult*/) throws ValidationException {
        // ValidationUtil.valid(bindingResult);

        //校验未复用，改用校验框架HibernateValidation
        // if (username != null && username.length() < 6) {
        //     return BaseRespVo.invalidData();
        // }
        // if (mobile != null && mobile.length() != 11) {
        //     return BaseRespVo.invalidData();
        // }

        CommonData<MarketUser> data = userService.list(info, user.getUsername(), user.getMobile());
        return BaseRespVo.ok(data);
    }

    @RequestMapping("update")
    public BaseRespVo update(@RequestBody MarketUser user) {
        MarketUser data = userService.update(user);
        return BaseRespVo.ok(data);
    }

    @RequestMapping("detail")
    public BaseRespVo detail(Integer id) {
        MarketUser data =userService.detail(id);
        return BaseRespVo.ok(data);
    }
}
